# -*- coding: utf-8 -*-

# @Author: Chen Hua
# @Date  : 2019/01/11
# @Desc  : 周期定时任务

import logging
import os
import sys
from logging.handlers import TimedRotatingFileHandler, RotatingFileHandler

logger = logging.getLogger("main")
logger.setLevel(logging.INFO)

# 创建 handler 输出到文件
 #日志打印格式
#创建TimedRotatingFileHandler对象
log_file_handler = RotatingFileHandler("stockx.log", backupCount=2, encoding='utf-8')
##log_file_handler = logging.FileHandler("../stockx.log", encoding='utf-8', mode='w')
log_file_handler.setLevel(logging.INFO)

# handler 输出到控制台
ch = logging.StreamHandler(sys.stdout)
ch.setLevel(logging.INFO)

# 创建 logging format
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
log_file_handler.setFormatter(formatter)
ch.setFormatter(formatter)

# add the handlers to the logger
logger.addHandler(log_file_handler)
logger.addHandler(ch)

log = logger
